<?php
class Nota_model extends CI_Model{
	function add($id_sitio,$id_usuario,$comentario,$lat,$lng){
		$data = array(
			'id_sitio'			=>$id_sitio,
			'id_usuario'		=>$id_usuario,
			'comentario'		=>$comentario,
			'latitud'			=>$lat,
			'longitud'			=>$lng
		);
		
		if($this->db->insert('nota',$data)){
			$this->db->select('comentario , users.username, latitud, longitud, nota.id');
			$this->db->from('nota');
			$this->db->join('users','users.id = nota.id_usuario');
			$this->db->where('nota.id', $this->db->insert_id());
			return $this->db->get()->result();
		}
		return false;
		
	}
	
	function getNotes($id_site){
		$this->db->select('nota.id, comentario , users.username, latitud, longitud');
		$this->db->from('nota');
		$this->db->join('users','users.id = nota.id_usuario');
		$this->db->where('id_sitio', $id_site);
		return $this->db->get()->result();
	}
	
	function getUser($id_note){
		$this->db->select('id_usuario');
		$this->db->where('id',$id_note);
		return $this->db->get('nota')->result();
	}
	
	function eliminar($id_note){
		$this->db->where('id', $id_note);
		$this->db->delete('nota'); 
	}
}